package com.social.action;

import java.util.List;
import com.base.dialect.PaginationSupport;
import com.base.dao.model.Ret;
import com.base.dao.model.Grid;
import com.base.entity.QueryParams;
import com.base.util.StringUtil;
import com.social.daoEx.model.UserTopicCommentEx;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.lang.StringUtils;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import com.base.action.CoreController;
import com.social.dao.model.UserTopicComment;
import com.social.dao.model.UserTopicCommentExample;
import com.social.service.UserTopicCommentService;

/**
@author sun
*/
@RequestMapping("userTopicComment")
@Controller
@LoginFilter
public class UserTopicCommentController extends CoreController{

    @Autowired
    private UserTopicCommentService userTopicCommentService;

    @RequestMapping("/list")
	@ResponseBody
    public String list(Integer page, Integer rows,Integer id,String name){
    	PaginationSupport.byPage(page, rows);
		QueryParams.Builder builder = QueryParams.newBuilder();
		if (id != null){
			builder.put("id",id);
		}
		if (StringUtil.isNotBlank(name)){
			builder.setLike("name",name);
		}
    	List<UserTopicCommentEx> list = userTopicCommentService.selectList(builder);
      	return page(list);
    }

    @RequestMapping("/save")
	@ResponseBody
    public String save(UserTopicComment userTopicComment){
    	if (userTopicComment.getId() == null){
    		userTopicCommentService.insert(userTopicComment);
    	}else{
    		userTopicCommentService.updateByPrimaryKeySelective(userTopicComment);
    	}
       	return ok();
    }

    @RequestMapping("/findById")
	@ResponseBody
    public String find(Integer id){
    	UserTopicComment userTopicComment = userTopicCommentService.selectByPrimaryKey(id);
       	return ok(userTopicComment);
    }

    @RequestMapping("/del")
	@ResponseBody
    public String del(String id){
    	String[] ids = id.split(",");
    	for (String str : ids){
    		userTopicCommentService.deleteByPrimaryKey(Integer.parseInt(str));
    	}
       	return ok();
    }


}